# -*- coding: utf-8 -*-
'''
@author: olivia.dou
Created on: 2020/4/27 17:01
desc:
'''
import logging,traceback
from util.db_util import execute_query

def get_item_code(item_name):
    """获取指定字典名称code

    :param item_name: 字典名称

    :return: 字典code
    """
    sql = "select item_code from t_das_lookup_static where item_name='%s'"%item_name

    try:
        res = execute_query(sql)
        return res[0][0]
    except Exception as e:
        logging.error(e)
        traceback.print_exc()
        return ""


def get_static_attrs_id(item_group):
    """获取指定字典集id

    :param item_group: 字典集名称

    :return: 字典集id
    """
    results = execute_query(
        "SELECT id FROM `t_das_lookup_static_group_attr` WHERE item_group='%s'" % item_group)
    try:
        result = results[0][0]
        return result
    except Exception as e:
        logging.error("no result retrieved")
        return None

def get_static_items_id(item_group,item_name):
    """获取指定字典集下数据id

    :param item_group: 字典名称
    :param item_name: 数据名称

    :return: 字典集下数据id
    """
    results = execute_query(
        "SELECT id FROM `t_das_lookup_static` WHERE item_group='%s' AND item_name='%s'" % (item_group,item_name))
    try:
        result = results[0][0]
        return result
    except Exception as e:
        logging.error("no result retrieved")
        return None

